﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace LenderClearingHouse
{
  public partial class DocumentFolderEditControl : UserControlBase
  {
    object _dataItem = null;

    public object DataItem
    {
      get
      {
        return this._dataItem;
      }
      set
      {
        this._dataItem = value;
      }
    }

    protected override void OnInit(EventArgs e)
    {
      base.OnInit(e);
      this.DataBinding += new EventHandler(EditUserControl_DataBinding);
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void RefreshDDL()
    {
      ddlInvestorAdmin.Visible = chkInvestorAdmin.Checked;
      ddlInvestor.Visible = chkInvestor.Checked;
      ddlUser.Visible = chkUser.Checked;
      ddlEscrowUser.Visible = chkEscrowUser.Checked;
    }

    protected void Rights_CheckedChanged(object sender, EventArgs e)
    {
      RefreshDDL();
    }

    protected void EditUserControl_DataBinding(object sender, EventArgs e)
    {
      if (DataItem is GridInsertionObject)
      {
        chkInvestorAdmin.Checked = false;
        chkInvestor.Checked = false;
        chkUser.Checked = false;
        chkEscrowUser.Checked = false;

        RefreshDDL();
      }
      else
      {
        string role;

        role = (string)DataBinder.Eval(DataItem, "InvestorAdminRole");
        chkInvestorAdmin.Checked = (role != "NA");
        if (role != "NA")
          ddlInvestorAdmin.SelectedValue = role;

        role = (string)DataBinder.Eval(DataItem, "InvestorRole");
        chkInvestor.Checked = (role != "NA");
        if (role != "NA")
          ddlInvestor.SelectedValue = role;

        role = (string)DataBinder.Eval(DataItem, "UserRole");
        chkUser.Checked = (role != "NA");
        if (role != "NA")
          ddlUser.SelectedValue = role;

        role = (string)DataBinder.Eval(DataItem, "EscrowUserRole");
        chkEscrowUser.Checked = (role != "NA");
        if (role != "NA")
          ddlEscrowUser.SelectedValue = role;

        RefreshDDL();
      }

    }
  }
}